﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using hlavny.modul1;

namespace hlavny.modul2
{
    [Serializable]
    public class CAttribute : IComparable
    {
        private int id = 0;
        private int table = 0;
        private string name = null;
        private CTypes.EnumTypes type = CTypes.EnumTypes.Character;
        private int length = 0;
        private bool isNull = false;

        #region CAttribute properties

        public int Id
        {
            get { return id; }
            set { id = value; }
        }
        public int Table
        {
            get { return table; }
            set { table = value; }
        }
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        public CTypes.EnumTypes Type
        {
            get { return type; }
            set { type = value; }
        }
        public int Length
        {
            get { return length; }
            set { length = value; }
        }
        public bool IsNull
        {
            get { return isNull; }
            set { isNull = value; }
        }

        #endregion

        #region CAttributes constructor overloads

        public CAttribute(int id)
        {
            this.id = id;
        }
        public CAttribute(int id, int table)
        {
            this.id = id;
            this.table = table;
        }
        public CAttribute(int id, string name, CTypes.EnumTypes type, int length, bool isNull)
        {
            this.id = id;
            this.name = name;
            this.type = type;
            this.length = length;
            this.isNull = isNull;
        }
        public CAttribute(int id, int table, string name, CTypes.EnumTypes type, int length, bool isNull)
        {
            this.id = id;
            this.table = table;
            this.name = name;
            this.type = type;
            this.length = length;
            this.isNull = isNull;
        }

        #endregion

        #region IComparable Members

        public int CompareTo(object obj)
        {
            CAttribute tmp = obj as CAttribute;
            return this.id.CompareTo(tmp.Id);
        }

        #endregion

        #region ToString function override

        public override string ToString()
        {
            string result = "";
            result += this.name;
            result += " " + this.type.ToString();
            if (this.type == CTypes.EnumTypes.Character)
                result += "(" + this.length.ToString() + ")";
            if (this.isNull)
                result += " NULL";
            return result;
        } 

        #endregion
    }
}
